/**
 * @name: permission
 * @author: win10
 * @date: 2024/3/6 8:50
 * @description：permission
 * @update: 2024/3/6 8:50
 */
import router from "@/router";
const whiteList = ["/login", "/register"];

router.beforeEach((to, from, next) => {
  const token = localStorage.getItem("token");
  if (token) {
    if (to.path === "/login") {
      next({ path: "/" });
    } else {
      next();
    }
  } else {
    if (whiteList.indexOf(to.path) !== -1) {
      next();
    } else {
      next(`/login?redirect=${to.path}`);
    }
  }
});
router.afterEach((to, from) => {});
